<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<style>
    xm-select > .xm-body{
        overflow-y: auto;
        height: 359px;
    }
</style>
<body>
<form class="layui-form layui-form-pane" id="operatePage">
    <div class="page-title"><div class="page-title-con"><span>编辑收入科目</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">

        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">上级名称</label>
                        <div class="layui-input-block">
                            <div id="pid"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" id="name" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-block">
                            <div class="radio-block">
                                <input type="radio" name="status" lay-filter="status" checked value="1" title="正常">
                                <input type="radio" name="status" lay-filter="status" value="0" title="停用">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;

    $("#operatePage").validate({
        rules: {
            name: {required: true},
        },
        messages:{
            name: {required: "请输入"},
        }
    });

    layui.use(['laytp', 'form', 'table'], function() {
        var form = layui.form, layer = layui.layer,table = layui.table;
        render_input_attr();
        facade.ajax({type: 'get', url: ask_engin_budshou_edit, data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data;
                $("#name").val(data.name);
                $("#explain").val(data.explain);
                var pidXmObj = xmselect_dan('pid', res.data.pidArr, data.pid, function (res) {

                });


                var status_str = '';
                if(data.status == 1){
                    status_str += '<input type="radio" name="status" checked value="1" title="正常">';
                    status_str += '<input type="radio" name="status" value="0" title="停用">';
                }else{
                    status_str += '<input type="radio" name="status" value="1" title="正常">';
                    status_str += '<input type="radio" name="status" checked value="0" title="停用">';
                }
                $('#statusDiv').html(status_str);

                render_from();
            }
        });

        form.on('submit(add)', function(data){
            var validRes = $("#operatePage").valid();
            if(!validRes){return false;}

            data.field.id = param_id;
            facade.ajax({url: ask_engin_budshou_edit, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    parent.searchTableFunc(form, table);
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });



</script>
</body>
</html>
